[13.x] Add toHtml() to Image - #60796
Conversation
|
Something Vite does, which is kinda cool, is gives you a control of how big an image is before it is rendered via a data URL vs referenced as an HTTP URL.
I wonder if there is something interesting we can do here, in tandem with a public disk, where generated images of smaller sizes are rendered as a data url and others are stored on a public disk and rendered as a http url, all handled seamlessly. Note that I haven't deep dived the image feature, so I don't know the internals or how things work under the hood to know if this totally makes sense as a suggestion. |
|
Note that attribute values aren't escaped in there, which means in the case of your example For example: Outputs: <img src="data:image/png;base64,…" width="100" height="100" alt=""><script>alert(document.cookie)</script>">At a minimum, wrapping the values in But I would suggest looking into how Blade components handle attributes in |
Co-authored-by: Stephen Rees-Carter <stephen@rees-carter.net>
and filter out invalid ones Co-authored-by: Ricardo Cerljenko <ricardo@lloyds-digital.com> See laravel#60796 (comment)
Co-authored-by: Ricardo Cerljenko <ricardo@lloyds-digital.com> See laravel#60796 (comment)
Co-authored-by: Ricardo Cerljenko <ricardo@lloyds-digital.com> See laravel#60796 (comment)
|
I think a component would be more appropriate to solve this problem. |
|
@browner12 I thought about that, too, but Laravel doesn't ship its own components, does it? |
@timacdonald Great idea, I thought about this as well, however,
|
|
AFAIK it doesn't currently, although I think there are some situations it should. Basically anytime we're using a method like this to spit out HTML, a component is IMO better suited to solve the problem. For example, I PR'ed a {!! $users->links() !!}it would be something like <x-laravel.pagination
:models="$users"
:perpage="5"
:showPages="true"
></x-laravel.pagination>I've been tempted to try this again lately, but Taylor obviously was uninterested before. If that's still the case, my opinion would be this belongs as a userland solution. |
Other things, I thought about but considered out of scope for now:
|
@browner12 Yeah, a penny for this man's thoughts … ^^ I mean, same with official enums, value objects, etc. Maybe, we first need an official |
@valorin Good catch! I went with the |
|
Thanks for your pull request to Laravel! Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include. If applicable, please consider releasing your code as a package so that the community can still take advantage of your contributions! |
Current
As you can see, information that have already been given above (
cover(400, 400)) have to be mirrored/duplicated within blade (width="400" height="400"), which can result in a lot of boilerplate.Proposed
This makes
Imageusable ergonomically within Blade as if it is a first-class citizen, just reusing what it already knows with the option to add more attributes: